<template>
	<view class="container-bottom-btns">
		<view class="form">
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.buildStuff.value">
				<view class="label">日租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额" v-model="hgProductMaterialLease.dayRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.buildStuff.value">
				<view class="label">月租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额" v-model="hgProductMaterialLease.monthRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.buildStuff.value">
				<view class="label">年租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额" v-model="hgProductMaterialLease.yearRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.device.value">
				<view class="label">月租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额" v-model="hgProductEquipmentLease.monthRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.device.value">
				<view class="label">台班租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额"  v-model="hgProductEquipmentLease.classRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType == 3 && productType2 == productType.device.value">
				<view class="label">小时租金</view>
				<view class="content">
					<input type="digit" placeholder="请输入金额"  v-model="hgProductEquipmentLease.hourRent"/>
				</view>
			</view>
			<view class="form-column-item" v-if="putType != 3">
				<view class="label">当前价格</view>
				<view class="content">
					<input type="digit" :value="oldShowPrice" disabled style="color:red" placeholder="请输入金额" />
				</view>
			</view>
			<view class="form-column-item" v-if="putType != 3">
				<view class="label">修改价格</view>
				<view class="content">
					<input type="digit" placeholder="请输入修改价格" v-model="showPrice"/>
				</view>
			</view>
		</view>
		
		<view class="bottom-btn-wrapper">
			<SubmitBtn text="保存" :customStyle="{width: '690rpx'}" @tap="submit"></SubmitBtn>
		</view>
	</view>
</template>

<script>
	import validate from '@/utils/validate.js'
	import { changePrice, getProductDetail } from '@/api/product.js'
	import { productType, sellType } from '../../consts'
import { toast } from '../../utils/uni-api'
	export default {
		data() {
			return {
				id: '',
				productType,
				sellType,
				oldShowPrice: '',
				productType2: 1,
				putType: 1,
				isSku: 1,
				showPrice: '',
				// 租赁设备
				hgProductEquipmentLease: {
					id:'',
					monthRent: '',
					classRent: '',
					hourRent: ''
				},
				// 租赁建材
				hgProductMaterialLease: {
					id:'',
					dayRent: '',
					monthRent: '',
					yearRent: ''
				}
			}
		},
		onLoad(option){
			this.id = option.id || ''	
			this.getProductDetail()
		},
		methods: {
			getProductDetail(){
				getProductDetail({id: this.id}).then(res => {
					this.productType2 = res.result.product_type
					this.putType = res.result.put_type
					this.isSku = res.result.is_sku
					this.showPrice = res.result.show_price
					if(this.putType != 3){
						this.oldShowPrice = '￥' + res.result.show_price
					}else{
						// 租赁设备
						if(this.productType2 === productType.device.value){
							this.hgProductEquipmentLease.id = res.result.hgProductEquipmentLease.id
							this.hgProductEquipmentLease.monthRent = res.result.hgProductEquipmentLease.monthRent
							this.hgProductEquipmentLease.classRent = res.result.hgProductEquipmentLease.classRent
							this.hgProductEquipmentLease.hourRent = res.result.hgProductEquipmentLease.hourRent
						}else{
							this.hgProductMaterialLease.id = res.result.hgProductMaterialLease.id
							this.hgProductMaterialLease.monthRent = res.result.hgProductMaterialLease.monthRent
							this.hgProductMaterialLease.dayRent = res.result.hgProductMaterialLease.dayRent
							this.hgProductMaterialLease.yearRent = res.result.hgProductMaterialLease.yearRent
						}
					}
				})
			},
			submit(){
				if(this.putType != 3){
					if(!validate.isNotEmpty(this.showPrice, '修改价格')) return
					if(!validate.isNotZero(this.showPrice, '修改价格')) return
				}else{
					// 租赁设备
					if(this.productType2 === productType.device.value){
						if(!validate.isNotEmpty(this.hgProductEquipmentLease.monthRent, '月租金')) return
						if(!validate.isNotZero(this.hgProductEquipmentLease.monthRent, '月租金')) return
						if(!validate.isNotZero(this.hgProductEquipmentLease.classRent, '台班租金')) return
						if(!validate.isNotZero(this.hgProductEquipmentLease.classRent, '台班租金')) return
						if(!validate.isNotZero(this.hgProductEquipmentLease.hourRent, '小时租金')) return
						if(!validate.isNotZero(this.hgProductEquipmentLease.hourRent, '小时租金')) return
					}else{
						if(!validate.isNotZero(this.hgProductMaterialLease.dayRent, '日租金')) return
						if(!validate.isNotZero(this.hgProductMaterialLease.dayRent, '日租金')) return
						if(!validate.isNotEmpty(this.hgProductMaterialLease.monthRent, '月租金')) return
						if(!validate.isNotZero(this.hgProductMaterialLease.monthRent, '月租金')) return
						if(!validate.isNotZero(this.hgProductMaterialLease.yearRent, '年租金')) return
						if(!validate.isNotZero(this.hgProductMaterialLease.yearRent, '年租金')) return
					}
				}
				changePrice({
					id: this.id,
					showPrice: this.showPrice,
					isSku: this.isSku,
					productType: this.productType2,
					putType: this.putType,
					hgProductMaterialLease: this.hgProductMaterialLease,
					hgProductEquipmentLease: this.hgProductEquipmentLease
				}).then(res => {
					uni.setStorageSync('refresh', 1);
					toast(res.message, true)
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				})
			}
		}
	}
</script>

<style>

</style>